const express = require("express");
const app = express();
const router = require("./router/index.js");

app.get("/test", (req, res) => {
  res.send("Hello World!");
});

//express处理表单post数据，无法从req.body直接读取，须在路由之前加载并设置json和urlencoded
app.use(express.json());
app.use(express.urlencoded({ extended: false }));

app.use("/", router);

const port = 3000;
app.listen(port, function () {
  console.log(
    "\n   ___ _____   ___\n" +
      "  / __|_   _| / __| ___ _ ___ _____ _ _\n" +
      " | (_ | | |   \\__ \\/ -_) '_\\ V / -_) '_|\n" +
      "  \\___| |_|   |___/\\___|_|  \\_/\\___|_|\n\n"
  );
  console.log(`App listening on port ${port}!`);
});
